package com.wslds.base.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AppContext {
	private static AppContext appContext = new AppContext();
	private ApplicationContext applicationContext;

	private AppContext() {
		try {
			applicationContext = new ClassPathXmlApplicationContext(
					new String[] {
							"classpath:spring.xml",
							"classpath:spring-other.xml"});
		} catch (Exception e) {
			throw new RuntimeException("获取spring的配置出错，请检查配置文件是否正确", e);
		}
	}

	private AppContext(String file) {
		try {
			applicationContext = new ClassPathXmlApplicationContext(
					new String[] { "dataSource.xml", file });
		} catch (Exception e) {
			throw new RuntimeException("获取spring的配置出错，请检查配置文件是否正确", e);
		}
	}

	public static AppContext getInstance() {
		return appContext;
	}

	public static AppContext getInstance(String file) {
		appContext = new AppContext(file);
		return appContext;
	}

	public ApplicationContext getApplicationContext() {
		return applicationContext;
	}
}
